//
//  ZZPayHandler.m
//  ExpertApp
//
//  Created by zhangxy on 2017/9/13.
//  Copyright © 2017年 sjhz. All rights reserved.
//

#import "ZZPayHandler.h"
#import "WXApi.h"

//#import <AlipaySDK/AlipaySDK.h>

@implementation ZZPayHandler

+(void) startJumppay:(ZZPayType) payType order:(NSDictionary *)params result:(void(^)(int code,NSString *msg)) payResult{
    
    
    
//   MBProgressHUD *mb = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].delegate.window];
//    [mb show:YES];
//    NSString *apiURL = korder_pay_weixin;
//     if(payType == ZZPayTypeZFB){
//        apiURL = korder_pay_zfb;
//    }
//    [NetworkUtil GET:apiURL parameters:params success:^(id responseObject) {
//        [mb hide:YES];
//        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        if ([dictionary[@"code"] integerValue] == kNetworkSuccessCode) {
//            if(payType == ZZPayTypeWX){
//                [self jumpToWXBizPay:dictionary result:payResult];
//            }else{
//                [self jumpToAliPay:dictionary result:payResult];
//            }
//        }
//        else{
//            [PopUtil showMessage:dictionary[@"message"] positionType:PopPositionTypeMiddle];
//        }
//
//    } failure:^(NSError *error) {
//        [mb hide:YES];
//        if(payResult){
//            payResult(1,@"请求支付信息失败!");
//        }
//    }];
}

+(void) startVipPay:(ZZPayType) payType order:(NSString *)orderId result:(void(^)(int code,NSString *msg)) payResult{
    
    
    
//    MBProgressHUD *mb = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].delegate.window];
//    [mb show:YES];
//    NSString *apiURL = kUserInfoOpenVip;
//    if(payType == ZZPayTypeZFB){
//        apiURL = kUserInfoOpenVipzfb;
//    }
//    [NetworkUtil GET:apiURL parameters:@{@"vip_id":orderId} success:^(id responseObject) {
//        [mb hide:YES];
//        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
//        if ([dictionary[@"code"] integerValue] == kNetworkSuccessCode) {
//            if(payType == ZZPayTypeWX){
//                [self jumpToWXBizPay:dictionary result:payResult];
//            }else{
//                [self jumpToAliPay:dictionary result:payResult];
//            }
//        }
//        else{
//            [PopUtil showMessage:dictionary[@"message"] positionType:PopPositionTypeMiddle];
//        }
//        
//    } failure:^(NSError *error) {
//        [mb hide:YES];
//        if(payResult){
//            payResult(1,@"请求支付信息失败!");
//        }
//    }];
}


+ (void)jumpToWXBizPay:(NSDictionary *) resultDict result:(void (^)(int code, NSString *msg))payResult{
//        NSDictionary *dict = [resultDict objectForKey:@"data"];
//        if (dict){
//            NSMutableString *stamp  = [dict objectForKey:@"timestamp"];
//
////            {
////                "code": 10000,
////                "data": {
////                    "appid": "wx77f5cfa32ff1b449",
////                    "partnerid": "1490337762",
////                    "prepayid": "wx20171114111027440f0da7cb0702637900",
////                    "package": "WXPay",
////                    "noncestr": "0f88de72a83b91a0ed7ac6e0b70befcb",
////                    "timestamp": 1510629027,
////                    "sign": "6A64A5E08C8FC3C6598B43CADCA44680"
////                }
////            }
//
//            //调起微信支付
//            PayReq* req             = [[PayReq alloc] init];
//            req.partnerId           = [dict objectForKey:@"partnerid"];
//            req.prepayId            = [dict objectForKey:@"prepayid"];
//            req.nonceStr            = [dict objectForKey:@"noncestr"];
//            req.timeStamp           = stamp.intValue;
//            req.package             = [dict objectForKey:@"package"];
//            req.sign                = [dict objectForKey:@"sign"];
//            BOOL isOK = [WXApi sendReq:req];
//            //日志输出
//            NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@ ---- %d",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign,isOK);
//
////            [[UIApplication sharedApplication].delegate.window makeToast:@"支付成功"];
////            payResult(0,[dict objectForKey:@"retmsg"]);
//        }else{
//            if(payResult){
//                payResult(2,@"服务器返回错误，未获取到支付对象");
//            }
//        }
    
}


+(void)jumpToAliPay:(NSDictionary *) dict result:(void (^)(int code, NSString *msg))payResult{
    //将签名成功字符串格式化为订单字符串,请严格按照该格式
    NSString *orderString = dict[@"data"];
    if (orderString != nil) {
//        NSString *signedString = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB";
//        orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",
//                       orderString, signedString, @"RSA"];
        
//        [[AlipaySDK defaultService] payOrder:orderString fromScheme:@"deerkids" callback:^(NSDictionary *resultDic) {
//            NSLog(@"reslut = %@",resultDic);
//
//
//        }];
    }
}

@end
